<?php


namespace app\common\service\message\lottery;


use app\common\model\Setting as SettingModel;
use app\common\service\message\Basics;

class Order extends Basics
{
    /**
     * 微信订阅消息通知用户
     * @return bool|mixed
     * @throws \app\common\exception\BaseException
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function send($order)
    {
        // 获取订阅消息配置
        $template = SettingModel::getItem('submsg', $order['wxapp_id'])['order']['delivery'];
        if (empty($template['template_id'])) {
            return false;
        }

        // 发送订阅消息
        return $this->sendWxSubMsg($order['wxapp_id'], [
            'touser' => $order['user']['open_id'],
            'template_id' => $template['template_id'],
            'page' => "",
            'data' => [
                // 订单号
                $template['keywords'][0] => ['value' => $order['order_no']],
                // 商品名称
                $template['keywords'][1] => ['value' => $order['goods']['goods_name']],
                // 收货人
                $template['keywords'][2] => ['value' => $order['username']],
                // 收货地址
                $template['keywords'][3] => ['value' => $order['address']],
                // 物流公司
                $template['keywords'][4] => ['value' => $order['express_name']],
            ]
        ]);
    }
}